// The top level CE Atlas control menu.

CE.WIDGETS.MENU = {
	
	navigation:{},
	
    // toggle open-closed.
	open: function(evt) {
		var bottom = $(evt.target).offset().top + $(evt.target).outerHeight() - 1;
		
        var $dlg = this.menus[evt.target.id].menu.$; 
        var was_open = $dlg.filter('*:visible').length;
		CE.WIDGETS.MENU.close_all();

		if (!was_open) $dlg.show()
            .css({
                top: bottom+'px'
            });
	},
	
	init:function() {
        this.menus = {
            ce_menu_map: CE.PLACE,
            ce_menu_theme: CE.THEME,
            ce_navigation_menu: CE.PLACE,
            ce_theme_menu: CE.THEME
        };
    },
	
    click: function(evt) {
        var parent_menu = $(evt.target).parents('.ce-menu-div').get(0);
        this.menus[parent_menu.id].menu.click(evt);
    },
    
	close_all: function() {
        $('.ce-menu-div').hide();
	}
};
